<?php

/** Zend_Controller_Action */
require_once ROOT_PATH . '/library/Soooner/Controller/WebAction.php';

class ShowController extends Soooner_Web_Controller_Action
{
	private $_modelScreen;
	private $_modelScreenlevelurl;
	private $_modelUrl;
	private $_modelHosts;
	public function init()
    {
    	$this->initDzTemplate(); 
    	$this->_modelScreen = new Model_Tables_Screen();
    	$this->_modelScreenlevelurl = new Model_Tables_Screenlevelurl(); 
    	$this->_modelUrl = new Model_Tables_Url(); 	
    	$this->_modelHosts = new Model_Tables_Hosts();
    }
    /**
     * 监控屏框架页面，调用时回传入screenid参数,区分显示不同内容
     */
    public function indexAction(){
    	$play = 50000000;//刷新时间
    	$screenid = $this->_getParam('screenid');
    	$level = $this->_configs["level"];
    	$urllist0 = $this->_modelScreenlevelurl->getList(1,1000,$screenid,$level);
    	$urlmap = $this->_modelUrl->getUrlMap();
    	$infos = array();
    	foreach($urllist0 as $url){
    		$url["v"] = $urlmap[$url["urlid"]];
    		$newplay = $url["refresh"]*1000;
    		if($newplay <$play)
    			$play = $newplay ;
    		$infos[]=$url;
    	}
    	if(count($infos)==1){
    		$infos[] = $infos[0];
    	}
    	//echo "<pre>";
    	//print_r($urllist);exit;
        include $this->_dzTemplate->getFile( 'web/show.html' );
    }
    /**
     * 
     * 是否需要刷新框架页面
     */
    public function needflushAction(){
    	$screenid = $this->_getParam('screenid');
    	$info = $this->_modelScreen->getInfo($screenid);
    	$needflush = $info["needflush"];
    	if($needflush>0){
    		$newneedflush = $needflush -1;
    		$this->_modelScreen->modifyAjax($screenid, "needflush", $newneedflush);
    	}
    	else 
    		$newneedflush = 0;
    	echo $needflush;
    }
	/**
	 * 
	 * 测试信息
	 */
    public function monitorAction(){
    	$name = $this->_getParam('name');
    	echo "<div style='font-size:200pt'>$name</div>";
    	exit();
    }
    /**
     *显示地图信息
     *根据传入参数 t:hostdown|hosterror|hostall显示不同类型的数据
     */
    public function mapAction(){
    	$t = $this->_getParam('t');
    	include $this->_dzTemplate->getFile( 'web/baidumap.html' );
    }
    public function getMemv($k){
    	$memcache = new Memcache;
        $ok = $memcache->connect('127.0.0.1', 11211);
        if(!$ok)
        	return false;
        $result = $memcache->get($k);
        return $result;
    }
    /**
     * 
     * getjsons
     */
	public function getjsonAction(){
    	$callback = $this->_getParam('callback');
		$t = $this->_getParam('t');
    	$args = $this->_getParam('args');
   		$todate = date('Ymd H:i',time());
    	$fromdate =  date('Ymd H:i',time()-24*60*60);
    	//$imgstyle = "cfont=ffffff&ccanvas=000000&cbg=000000&stitle=13&full-size-mode=ture&caxis=ffffff";
    	$imgstyle = "cbg=111111&ccanvas=000000&cshadea=000000&cshadeb=000000&cgrid=333333&cmgrid=888888&cfont=ffffff&carrow=ffffff&caxis=ffffff&full-size-mode=true&slegend=13&saxis=13&width=902&height=450";
    	$imgstyle2 = "cbg=111111&ccanvas=000000&cshadea=000000&cshadeb=000000&cgrid=333333&cmgrid=888888&cfont=ffffff&carrow=ffffff&caxis=ffffff&full-size-mode=true&slegend=13&saxis=13&width=900&height=680";
		switch ($t){
		    case "live"://全网直播
		    	$r = array("online"=>$this->getMemv("mwall_live_online"),
				    	   "bandwidth"=>$this->getMemv("mwall_live_bandwidth"),
				    	   "onlineimg"=>"http://rtdata.vsdn.tv380.com/active_user.png?$imgstyle2&title=%E5%9C%A8%E7%BA%BF%E4%BA%BA%E6%95%B0($todate)&ds=active_user|total|AREA|32CD32|%E5%9C%A8%E7%BA%BF%E4%BA%BA%E6%95%B0&start=$fromdate&end=$todate&xgrid=&intf=live&units-exponent=0&base=1000",
				    	   "bandwidthimg"=>"http://rtdata.vsdn.tv380.com/bandwidth.png?$imgstyle2&title=%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD($todate)&ds=bandwidth|total|AREA|411445|%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD&start=$fromdate&end=$todate&xgrid=&intf=live&base=1024",
		    	);
		    	break;
			case "vod"://全网点播
				$r = array("online"=>$this->getMemv("mwall_vod_online"),
				    	   "bandwidth"=>$this->getMemv("mwall_vod_bandwidth"),
						   "onlineimg"=>"http://rtdata.vsdn.tv380.com/active_user.png?$imgstyle&title=%E5%9C%A8%E7%BA%BF%E4%BA%BA%E6%95%B0($todate)&ds=active_user|total|AREA|32CD32|%E5%9C%A8%E7%BA%BF%E4%BA%BA%E6%95%B0&start=$fromdate&end=$todate&xgrid=&intf=vod&&units-exponent=0",
						   "bandwidthimg"=>"http://rtdata.vsdn.tv380.com/bandwidth.png?$imgstyle&title=%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD($todate)&ds=bandwidth|total|AREA|411445|%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD&start=$fromdate&end=$todate&xgrid=&intf=vod&base=1024",
						   "hitimg"=>"http://rtdata.vsdn.tv380.com/hit.png?$imgstyle&title=%E5%91%BD%E4%B8%AD%E6%95%B0($todate)&ds=handled_request|total|AREA|778899|%E5%A4%84%E7%90%86%E7%9A%84%E8%AF%B7%E6%B1%82%E6%95%B0;hit|total|LINE|FF0000|%E5%91%BD%E4%B8%AD%E6%95%B0&start=$fromdate&end=$todate&xgrid=&intf=vod&&units-exponent=0",
						   "sourceimg"=>"http://rtdata.vsdn.tv380.com/back_source.png?$imgstyle&title=%E5%9B%9E%E6%BA%90%E5%B8%A6%E5%AE%BD($todate)&ds=back_source|total|AREA|DC143C|%E5%9B%9E%E6%BA%90%E5%B8%A6%E5%AE%BD&start=$fromdate&end=$todate&xgrid=&intf=vod&base=1024",
				);
		    	break;
		   case "web"://全网网页加速
				$r = array("online"=>$this->getMemv("mwall_web_online"),
				    	   "bandwidth"=>$this->getMemv("mwall_web_bandwidth"),
						   "onlineimg"=>"http://211.100.48.159/client_requests.png?$imgstyle&title=%E8%AF%B7%E6%B1%82%E6%95%B0($todate)&ds=client_requests|total|AREA|411445|%E8%AF%B7%E6%B1%82%E6%95%B0&start=$fromdate&end=$todate&xgrid=&intf=running&&units-exponent=0",
						   "bandwidthimg"=>"http://211.100.48.159/client_bandwidth.png?$imgstyle&title=%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)($todate)&ds=client_bandwidth|total|AREA|00CC33|%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)&start=$fromdate&end=$todate&xgrid=&intf=running&base=1024",
						   "gainimg"=>"http://211.100.48.159/gained_bandwidth.png?$imgstyle&title=%E5%B8%A6%E5%AE%BD%E5%A2%9E%E7%9B%8A(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)($todate)&ds=gained_bandwidth|total|AREA|FF0000|%E5%B8%A6%E5%AE%BD%E5%A2%9E%E7%9B%8A(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)&start=$fromdate&end=$todate&xgrid=&intf=running&base=1024",
						   "sourceimg"=>"http://211.100.48.159/server_bandwidth.png?$imgstyle&title=%E8%BE%93%E5%85%A5%E5%B8%A6%E5%AE%BD(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)($todate)&ds=server_bandwidth|total|AREA|32CD32|%E8%BE%93%E5%85%A5%E5%B8%A6%E5%AE%BD(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)&start=$fromdate&end=$todate&xgrid=&intf=running&base=1024",
				);
		    	break;
		   case "spbusilive"://客户业务直播
		   		$r = array("sp"=> $args,
		   				   "online"=>$this->getMemv("mwall_".strtoupper($args)."_live_online"),
				    	   "bandwidth"=>$this->getMemv("mwall_".strtoupper($args)."_live_bandwidth"),
				    	   "onlineimg"=>"http://rtdata.vsdn.tv380.com/active_user.png?$imgstyle2&title=%E5%9C%A8%E7%BA%BF%E4%BA%BA%E6%95%B0($todate)&ds=active_user|sp/$args|AREA|32CD32|%E5%9C%A8%E7%BA%BF%E4%BA%BA%E6%95%B0&start=$fromdate&end=$todate&xgrid=&intf=live&&units-exponent=0",
				    	   "bandwidthimg"=>"http://rtdata.vsdn.tv380.com/bandwidth.png?$imgstyle2&title=%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD($todate)&ds=bandwidth|sp/$args|AREA|411445|%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD&start=$fromdate&end=$todate&xgrid=&intf=live&base=1024"
		   		);
		    	break;
		   case "spbusivod"://客户业务点播
		   		$r = array("sp"=>$args,
		   				   "online"=>$this->getMemv("mwall_".strtoupper($args)."_vod_online"),
				    	   "bandwidth"=>$this->getMemv("mwall_".strtoupper($args)."_vod_bandwidth"),
				    	   "onlineimg"=>"http://rtdata.vsdn.tv380.com/active_user.png?$imgstyle&title=%E5%9C%A8%E7%BA%BF%E4%BA%BA%E6%95%B0($todate)&ds=active_user|sp/$args|AREA|32CD32|%E5%9C%A8%E7%BA%BF%E4%BA%BA%E6%95%B0&start=$fromdate&end=$todate&xgrid=&intf=vod&&units-exponent=0",
				    	   "bandwidthimg"=>"http://rtdata.vsdn.tv380.com/bandwidth.png?$imgstyle&title=%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD($todate)&ds=bandwidth|sp/$args|AREA|411445|%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD&start=$fromdate&end=$todate&xgrid=&intf=vod&base=1024",
		   				   "hitimg"=>"http://rtdata.vsdn.tv380.com/hit.png?$imgstyle&title=%E5%91%BD%E4%B8%AD%E6%95%B0($todate)&ds=handled_request|sp/$args|AREA|778899|%E5%A4%84%E7%90%86%E7%9A%84%E8%AF%B7%E6%B1%82%E6%95%B0;hit|sp/$args|LINE|FF0000|%E5%91%BD%E4%B8%AD%E6%95%B0&start=$fromdate&end=$todate&xgrid=&intf=vod&&units-exponent=0",
						   "sourceimg"=>"http://rtdata.vsdn.tv380.com/back_source.png?$imgstyle&title=%E5%9B%9E%E6%BA%90%E5%B8%A6%E5%AE%BD($todate)&ds=back_source|sp/$args|AREA|DC143C|%E5%9B%9E%E6%BA%90%E5%B8%A6%E5%AE%BD&start=$fromdate&end=$todate&xgrid=&intf=vod&base=1024",
		   		);
		    	break;
		   case "spbusiweb"://客户业务网页
		   		$r = array("sp"=>$args,
		   				   "online"=>$this->getMemv("mwall_".strtoupper($args)."_web_online"),
				    	   "bandwidth"=>$this->getMemv("mwall_".strtoupper($args)."_web_bandwidth"),
				    	   "onlineimg"=>"http://211.100.48.159/client_requests.png?$imgstyle&title=%E8%AF%B7%E6%B1%82%E6%95%B0($todate)&ds=client_requests|bizuser/$args|AREA|411445|%E8%AF%B7%E6%B1%82%E6%95%B0&start=$fromdate&end=$todate&xgrid=&intf=bizuser&&units-exponent=0",
				    	   "bandwidthimg"=>"http://211.100.48.159/client_bandwidth.png?$imgstyle&title=%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)($todate)&ds=client_bandwidth|bizuser/$args|AREA|00CC33|%E8%BE%93%E5%87%BA%E5%B8%A6%E5%AE%BD(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)&start=$fromdate&end=$todate&xgrid=&intf=bizuser&base=1024",
		   				   "gainimg"=>"http://211.100.48.159/gained_bandwidth.png?$imgstyle&title=%E5%B8%A6%E5%AE%BD%E5%A2%9E%E7%9B%8A(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)($todate)&ds=gained_bandwidth|bizuser/$args|AREA|FF0000|%E5%B8%A6%E5%AE%BD%E5%A2%9E%E7%9B%8A(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)&start=$fromdate&end=$todate&xgrid=&intf=bizuser&base=1024",
						   "sourceimg"=>"http://211.100.48.159/server_bandwidth.png?$imgstyle&title=%E8%BE%93%E5%85%A5%E5%B8%A6%E5%AE%BD(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)($todate)&ds=server_bandwidth|bizuser/$args|AREA|32CD32|%E8%BE%93%E5%85%A5%E5%B8%A6%E5%AE%BD(%E5%8D%95%E4%BD%8D%EF%BC%9Abps)&start=$fromdate&end=$todate&xgrid=&intf=bizuser&base=1024",
		   		);
		    	break;
		   case "hosts"://主机监控
		   		$r1 = $this->getMemv("mwall_hosts_area");
		   		$r2 = $this->getMemv("mwall_hosts_down_list");
		   		$r["area"] = json_decode($r1,true);
		   		$r["downlist"] = json_decode($r2,true);
		   		break;
		   case "bandused":
		   		$r0 = $this->getMemv("mwall_band_used");
		   		$r = json_decode($r0,true);
		   		break;
		   case "dev1":
		   		$r_dns = $this->getMemv("mwall_hosts_dns_list");	
		   		$r_db = $this->getMemv("mwall_hosts_db_list");
		   		$r_gslb = $this->getMemv("mwall_hosts_gslb_list");
		   		$r["dns"] = json_decode($r_dns,true);
		   		$r["db"] = json_decode($r_db,true);
		   		$r["gslb"] = json_decode($r_gslb,true);
		   		break;
		   	case "dev2":
		   		$r_auth = $this->getMemv("mwall_hosts_auth_list");
		   		$r_data = $this->getMemv("mwall_hosts_data_list");
		   		$r_sbs_health = $this->getMemv("mwall_hosts_sbs_health_list");
		   		$r["auth"] = json_decode($r_auth,true);
		   		$r["data"] = json_decode($r_data,true);
		   		$r["sbs"] = json_decode($r_sbs_health,true);
		   		break;
		   default:
		     	$r = array(array("error"=>"no type!"));
		}
	   	$jsonr = json_encode($r);
	   	if($callback){
	   		echo $callback ."(". $jsonr .");";
	   	}    	
    	exit();
    }
}